package com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.order;

import com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * @author huan.xu
 * @date 2021/10/3 22:23
 * @description 简单工厂
 */
public class SimpleFactory {

  /**
   * 创建披萨
   *
   * @param pizzaType
   * @return
   */
  public Pizza createPizza(String pizzaType) {
    System.out.println("使用简单工厂模式");
    Pizza pizza = null;

    if ("cheese".equals(pizzaType)) {
      pizza = new CheesePizza();
    } else if ("greek".equals(pizzaType)) {
      pizza = new GreekPizza();
    } else if ("pepper".equals(pizzaType)) {
      pizza = new PepperPizza();
    }
    if (pizza != null) {
      pizza.setName(pizzaType);
    }
    return pizza;
  }
}
